home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / opalvisn / jopalif.lha / Opal.f < prev    next >
Text File  |  1993-01-01  |  14KB  |  509 lines

  1. \ JForth Language Interface for OpalVision's Opal.Library
  2. \
  3. \ Version 1.0 - 31 December 1992
  4. \
  5. \ By Marlin Schwanke
  6.  
  7. include? OpalScreen ji:opal/opallib.j
  8.  
  9. ANEW TASK-OPAL
  10.  
  11. \ JForth Amiga shared library words
  12.  
  13. :Library opal
  14. : opal? ( -- ) opal_NAME opal_LIB lib? ;
  15. : -opal ( -- ) opal_LIB -lib ;
  16.  
  17. \ Some useful macros
  18.  
  19. \ Set 24 bit pen value
  20. : SetPen24 ( OpalScreen, Red8, Green8, Blue8 -- , Store 24 bitplane pen )
  21.    >r >r                ( Now have OS R8 )
  22.    over ..! OS_Pen_R     ( Store red pen )
  23.    r> over ..! OS_Pen_G  ( Store green pen )
  24.    r> swap ..! OS_Pen_B  ( Store blue pen
  25. ;
  26.  
  27. \ Set 15 bit pen value
  28. : SetPen15 ( OpalScreen Red5 Green5 Blue5 -- , Store 15 bitplane pen )
  29.    31 and >r 31 and swap 31 and        ( Now have OS 000GGGGG 000RRRRR )
  30.    2 shift over  24 and -3 shift or    ( Now have OS 0RRRRRGG )
  31.    swap 7 and 5 shift r> or            ( Now have OS 0RRRRRGG GGGBBBBB )
  32.    2 pick ..! OS_Pen_G                  ( Store green pen )
  33.    swap ..! OS_Pen_R                    ( Store red pen )
  34. ;
  35.  
  36. \ Set 8 bit pallette mapped pen value
  37. : SetPen8P ( OpalScreen Pen8 -- , Store 8 bitplane pen )
  38.    swap ..! OS_Pen_R
  39. ;
  40.  
  41. \ Set 8 bit pen value
  42. : SetPen8
  43.    3 and >r 7 and swap 7 and           ( Now have OS G3 R3 )
  44.    5 shift swap 2 shift or r> or       ( Now have OS RRRGGGBB )
  45.    swap ..!  OS_Pen_R                   ( Store Pen_R )
  46. ;
  47.  
  48. \ Get 24 bit pen values
  49. : GetPen24 ( OpalScreen -- Red8 Green8 Blue8 , Get the current 24 bitplane pen )
  50.    dup ..@ OS_Pen_R        ( Now have OS Pen_R )
  51.    swap dup ..@ OS_Pen_G   ( Now have Pen_R OS Pen_G )
  52.    swap ..@ OS_Pen_B       ( Now have Pen_R Pen_G Pen_B )
  53. ;
  54.  
  55. \ Get 15 bit pen values
  56. : GetPen15 ( OpalScreen -- Red5 Green5 Blue5 , Get the current 15 bitplane pen )
  57.    dup ..@ OS_Pen_R                    ( Now have OS 0RRRRRGG )
  58.    dup -2 shift                        ( Now have OS 0RRRRRGG 000RRRRR )
  59.    swap 3 and 3 shift                  ( Now have OS 000RRRRR 000GG000 )
  60.    rot ..@ OS_Pen_G                    ( Now have 000RRRRR 000GG000 GGGBBBBB )
  61.    swap over 224 and -5 shift or       ( Now have 000RRRRR GGGBBBBB 000GGGGG )
  62.    swap 31 and                         ( Now have 000RRRRR 000GGGGG 000BBBBB )
  63. ;
  64.  
  65. \ Get 8 bit palette mapped pen value
  66. : GetPen8P ( OpalScreen -- Pen8 , Get the current 8 bitplane pen )
  67.    ..@ OS_Pen_R
  68. ;
  69.  
  70. \ Get 8 bit pen values
  71. : GetPen8 ( OpalScreen -- Red3 Green3 Blue2 )
  72.    ..@ OS_Pen_R
  73.    dup -5 shift            ( Now have OS 00000RRR )
  74.    over 28 and -2 shift    ( Now have OS 00000RRR 00000GGG )
  75.    rot 3 and               ( Now have 00000RRR 00000GGG 000000BB )
  76. ;
  77.  
  78. \ Get 24 bit color values
  79. : GetCol24 ( OpalScreen -- Red8, Green8 , Blue 8 , Get ReadPixel24 24 bitplane color values )
  80.    dup ..@ OS_Red       ( Now have OS Red8 )
  81.    over ..@ OS_Green    ( Now have OS Red8 Green8 )
  82.    rot ..@ OS_Blue      ( Now have Red8 Green8 Blue8 )
  83. ;
  84.  
  85. \ Get 15 bit color values
  86. : GetCol15 ( OpalScreen -- Red5 Green5 Blue5 , Get ReadPixel24 15 bitplane color values )
  87.    dup ..@ OS_Red                   ( Now have OS 0RRRRRGGG )
  88.    dup -2 shift                     ( Now have OS 0RRRRRGG 000RRRRR )
  89.    swap 3 and 3 shift               ( Now have OS 000RRRRR 000GG000 )
  90.    rot ..@ OS_Green                 ( Now have 000RRRRR 00000GG GGGBBBBB )
  91.    swap over 224 and -5 shift or    ( Now have 000RRRRR GGGBBBBB 000GGGGG )
  92.    swap 31 and                      ( Now have 000RRRRR 000GGGGG 000BBBBB )
  93. ;
  94.  
  95. \ Get 8 bit palette mapped color value
  96. : GetCol8P ( OpalScreen -- Col8 , Get ReadPixel24 8 bitplane color value )
  97.    ..@ OS_Red
  98. ;
  99.  
  100. \ Get 8 bit color values
  101. : GetCol8 ( OpalScreen -- Red3 Green3 Blue2 )
  102.    ..@ OS_Red
  103.    dup -5 shift            ( Now have OS 00000RRR )
  104.    over 28 and -2 shift    ( Now have OS 00000RRR 00000GGG )
  105.    rot 3 and               ( Now have 00000RRR 00000GGG 000000BB )
  106. ;
  107.  
  108. \ Playfield & Priority stencil pens
  109. : SetPFPen ( Opalscreen State -- Set playfield pen to state )
  110.    swap ..! OS_Pen_R
  111. ;
  112.  
  113. : SetPRPen ( OpalScreen State -- Set priority pen to state )
  114.    swap ..! OS_Pen_R
  115. ;
  116.  
  117. \ Opal Library Calls
  118.  
  119. \ Note that all addresses are JForth relative going into and coming out of these
  120. \ routines.  The code for each call handles the necessary transformations.  Also
  121. \ note that all filenames must be 0 terminated 'C' style strings.
  122.  
  123. : OpenScreen24()  ( Modes -- Screen/Null )
  124. \ Allocates all resources and displays an OpalVision screen.
  125.    call Opal_LIB OpenScreen24 if>rel
  126. ;
  127.  
  128. : CloseScreen24() ( -- )
  129. \ Stop current display and free resources.
  130.    callvoid Opal_LIB CloseScreen24
  131. ;
  132.  
  133. : WritePixel24() ( Screen X Y -- Result )
  134. \ Write pixel into an OpalScreen.
  135.    call>abs Opal_LIB WritePixel24
  136. ;
  137.  
  138. : ReadPixel24() ( Screen X Y -- Result )
  139. \ Returns colour information for a given pixel.
  140.    call>abs Opal_LIB ReadPixel24
  141. ;
  142.  
  143. : ClearScreen24() ( Screen -- )
  144. \ Clears all bitplanes in a screen.
  145.    callvoid>abs Opal_LIB ClearScreen24
  146. ;
  147.  
  148. : ILBMtoOV() ( Screen ILBMData SourceWidth Lines TopLine Planes -- )
  149. \ Convert interleaved bitmap to OpalVision format.
  150.    callvoid>abs Opal_LIB ILBMtoOV
  151. ;
  152.  
  153. : UpdateDelay24() ( Frames -- )
  154. \ Sets the delay between consecutive frame buffer updates.
  155.    callvoid Opal_LIB UpdateDelay24
  156. ;
  157.  
  158. : Refresh24() ( -- )
  159. \ Refreshes the frame buffer.
  160.    callvoid Opal_LIB Refresh24
  161. ;
  162.  
  163. : SetDisplayBottom24() ( BottomLine -- Result )
  164. \ Sets the lower limit of the OpalVision screen.
  165.    call Opal_LIB SetDisplayBottom24
  166. ;
  167.  
  168. : ClearDisplayBottom24() ( -- )
  169. \ Clears the OpalVision display bottom setting.
  170.    callvoid Opal_LIB ClearDisplayBottom24
  171. ;
  172.  
  173. : SetSprite24() ( SpriteData SpriteNumber -- )
  174. \ Allows Amiga sprites to be displayed over OpalVision graphics.
  175.    callvoid>abs Opal_LIB SetSprite24
  176. ;
  177.  
  178. : AmigaPriority() ( -- )
  179. \ Gives Amiga graphics priority over OpalVision display.
  180.    callvoid Opal_LIB AmigaPriority
  181. ;
  182.  
  183. : OVPriority() ( -- )
  184. \ Give OpalVision graphics priority over the Amiga graphics.
  185.    callvoid Opal_LIB OVPriority
  186. ;
  187.  
  188. : DualDisplay24() ( -- )
  189. \ Sets up an Amiga/OpalVision dual display.
  190.    callvoid Opal_LIB DualDisplay24
  191. ;
  192.  
  193. : SingleDisplay24() ( -- )
  194. \ Sets up an Amiga/OpalVision single display.
  195.    callvoid Opal_LIB SingleDisplay24
  196. ;
  197.  
  198. : AppendCopper24() ( CopperArray -- )
  199. \ Attaches user copper lists to existing display copper lists.
  200.    callvoid>abs Opal_LIB AppendCopper24
  201. ;
  202.  
  203. : RectFill24() ( OScrn Left Top Bottom Right -- )
  204. \ Draws a solid rectangle.
  205.    callvoid>abs Opal_LIB RectFill24
  206. ;
  207.  
  208. : UpdateCoPro24() ( -- )
  209. \ Writes CoPro list for current the display screen to Video coprocessor.
  210.    callvoid Opal_LIB UpdateCoPro24
  211. ;
  212.  
  213. : SetControlBit24() ( FrameNumber BitNumber State -- )
  214. \ Modifies a bit in the control line register.
  215.    callvoid Opal_LIB SetControlBit24
  216. ;
  217.  
  218. : PaletteMap24() ( PaletteMap -- )
  219. \ Enable/Disable palette mapping.
  220.    callvoid Opal_LIB PaletteMap24
  221. ;
  222.  
  223. : UpdatePalette24() ( -- )
  224. \ Loads all 256 entries of Red, Green, and Blue values in the OpalScreen
  225. \ structure into the OpalVision palette registers.
  226.    callvoid Opal_LIB UpdatePalette24
  227. ;
  228.  
  229. : Scroll24() ( DeltaX DeltaY -- )
  230. \ Scrolls currently displayed OpalVision image.
  231.    callvoid Opal_LIB Scroll24
  232. ;
  233.  
  234. : LoadIff24() ( OpalScreen 0Filename Flags -- OpalScreen/Error )
  235. \ Loads an image file.
  236.    >r >abs swap            ( fn scr scr )
  237.    if>abs                  ( fn scr/0 )
  238.    swap r>                 ( scr/0 fn fl )
  239.    call Opal_LIB LoadIff24 ( scr/error )
  240.    dup OL_ERR_MAXERR >=    ( scr/error )
  241.    if >rel then            ( scr/error )
  242. ;
  243.  
  244. : LoadImage24() ( OpalScreen 0Filename Flags -- OpalScreen/Error )
  245. \ Alias for LoadIff24().
  246.    LoadIFF24()
  247. ;
  248.  
  249. : SetScreen24() ( OpalScreen -- )
  250. \ Fills screen with a specified colour.
  251.    callvoid>abs Opal_LIB SetScreen24
  252. ;
  253.  
  254. : SaveIFF24() ( OpalScreen 0Filename ChunkFunction Flags -- Result )
  255. \ Save an OpalScreen as an IFF file.
  256.    call>abs Opal_LIB SaveIFF24
  257. ;
  258.  
  259. : CreateScreen24() ( ScreenModes Width Height -- OpalScreen/Null )
  260. \ Create an arbitrarily sized virtual OpalScreen.
  261.    call Opal_LIB CreateScreen24 if>rel
  262. ;
  263.  
  264. : FreeScreen24() ( OpalScreen -- )
  265. \ Frees a virtual OpalScreen.
  266.    callvoid>abs Opal_LIB FreeScreen24
  267. ;
  268.  
  269. : UpdateRegs24() ( -- )
  270. \ Updates the hardware registers for the current display screen.
  271.    callvoid Opal_LIB UpdateRegs24
  272. ;
  273.  
  274. : SetLoadAddress24() ( -- )
  275. \ Updates the OpalVision load address register.
  276.    callvoid Opal_LIB SetLoadAddress24
  277. ;
  278.  
  279. : RGBtoOV() ( OpalScreen RGBPlanes Top Left Width height -- )
  280. \ Convert three planes of RGB to OpalVision bitplane data.
  281.    callvoid>abs Opal_LIB RGBtoOV
  282. ;
  283.  
  284. : ActiveScreen24() ( -- OpalScreen/Null )
  285. \ Provides a pointer to the currently displayed OpalVision screen.
  286.    call Opal_LIB ActiveScreen24 if>rel
  287. ;
  288.  
  289. : FadeIn24() ( Time -- )
  290. \ Fades display in from black.
  291.    callvoid Opal_LIB FadeIn24
  292. ;
  293.  
  294. : FadeOut24() ( Time -- )
  295. \ Fade display to black.
  296.    callvoid Opal_LIB FadeOut24
  297. ;
  298.  
  299. : ClearQuick24() ( -- )
  300. \ Clears frame buffer memory.
  301.    callvoid Opal_LIB ClearQuick24
  302. ;
  303.  
  304. : WriteThumbnail24() ( OpalScreen File -- Result )
  305. \ Writes an IFF thumb-nail chunk into a file.
  306.    callvoid>abs Opal_LIB WriteThumbnail24
  307. ;
  308.  
  309. : SetRGB24() ( Entry Red Green Blue -- )
  310. \ Updates a single palette entry to the OpalVision palette registers.
  311.    callvoid Opal_LIB SetRGB24
  312. ;
  313.  
  314. : DrawLine24() ( OpalScreen X1 Y1 X2 Y2 -- )
  315. \ Draws a line into an OpalScreen.
  316.    callvoid>abs Opal_LIB DrawLine24
  317. ;
  318.  
  319. : StopUpdate24() ( -- )
  320. \ Stops updates to the frame buffer memory.
  321.    callvoid Opal_LIB StopUpdate24
  322. ;
  323.  
  324. : WritePFPixel24() ( OpalScreen X Y -- )
  325. \ Set or clear a pixel in the playfield stencil.
  326.    callvoid>abs Opal_LIB WritePFPixel24
  327. ;
  328.  
  329. : WritePRPixel24() ( OpalScreen X Y -- )
  330. \ Set or clear a pixel in the priority stencil.
  331.    callvoid>abs Opal_LIB WritePRPixel24
  332. ;
  333.  
  334. : OVtoRGB() ( OpalScreen RGBPlanes Top Left Width Height -- )
  335. \ Converts OpalVision bitplane data to three planes of RGB
  336.    callvoid>abs Opal_LIB OVtoRGB
  337. ;
  338.  
  339. : OVtoILBM() ( OpalScreen ILBMData DestWidth Lines TopLine -- )
  340. \ Convert OpalVision bit planes to interleaved bitmap format.
  341.    callvoid>abs Opal_LIB OVtoILBM
  342. ;
  343.  
  344. : UpdateAll24() ( -- )
  345. \ Resets the internal update stucture so all required banks are updated.
  346.    callvoid Opal_LIB UpdateAll24
  347. ;
  348.  
  349. : UpdatePFStencil24() ( -- )
  350. \ Updates playfield stencil at highest possible rate.
  351.    callvoid Opal_LIB UpdatePFStencil24
  352. ;
  353.  
  354. : EnablePRStencil24() ( -- )
  355. \ Enables the use of the priority stencil in dual display mode.
  356.    callvoid Opal_LIB EnablePRStencil24
  357. ;
  358.  
  359. : DisablePRStencil24() ( -- )
  360. \ Disables the use of the priority stencil in dual display mode.
  361.    callvoid Opal_LIB DisablePRStencil24
  362. ;
  363.  
  364. : ClearPRStencil24() ( OpalScreen -- )
  365. \ Clears the priority stencil of the specified screen.
  366.    callvoid>abs Opal_LIB ClearPRStencil24
  367. ;
  368.  
  369. : SetPRStencil24() ( OpalScreen -- )
  370. \ Sets the priority stencil of the specified screen.
  371.    callvoid>abs Opal_LIB SetPRStencil24
  372. ;
  373.  
  374. : DisplayFrame24() ( Frame -- )
  375. \ Sets the currently displayed frame within the frame buffer memory.
  376.    callvoid Opal_LIB DisplayFrame24
  377. ;
  378.  
  379. : WriteFrame24() ( Frame -- )
  380. \ Sets the current frame to be written within the frame buffer memory.
  381.    callvoid Opal_LIB WriteFrame24
  382. ;
  383.  
  384. : BitPlanetoOV() ( OpalScreen ScrPlanes ScrWidth Lines TopLine ScrDepth -- )
  385. \ Convert standard bitplane data to OpalVision format.
  386.    callvoid>abs Opal_LIB BitPlanetoOV
  387. ;
  388.  
  389. : SetCoPro24() ( InstructionNumber Instruction -- )
  390. \ Modifies a single instruction in the CoPro list.
  391.    callvoid Opal_LIB SetCoPro24
  392. ;
  393.  
  394. : RegWait24() ( -- )
  395. \ Wait for register update to complete.
  396.    callvoid Opal_LIB RegWait24
  397. ;
  398.  
  399. : DualPlayField24 ( -- )
  400. \ Sets up an OpalVision 24 bit dual playfield.
  401.    callvoid Opal_LIB DualPlayField24
  402. ;
  403.  
  404. : SinglePlayField24 ( -- )
  405. \ Set up an Amiga or OpalVision single playfield.
  406.    callvoid Opal_LIB SinglePlayField24
  407. ;
  408.  
  409. : ClearPFStencil24() ( OpalScreen -- )
  410. \ Clears the playfield stencil of the specified screen.
  411.    callvoid>abs Opal_LIB ClearPFStencil24
  412. ;
  413.  
  414. : SetPFStencil24() ( OpalScreen -- )
  415. \ Sets the playfield stencil of the specified screen.
  416.    callvoid>abs Opal_LIB SetPFStencil24
  417. ;
  418.  
  419. : ReadPRPixel24() ( OpalScreen X Y --  Result )
  420. \ Returns the state of a given priority stencil pixel.
  421.    call>abs Opal_LIB ReadPRPixel24
  422. ;
  423.  
  424. : ReadPFPixel24() ( OpalScreen X Y --  Result )
  425. \ Returns the state of a given playfield stencil pixel.
  426.    call>abs Opal_LIB ReadPFPixel24
  427. ;
  428.  
  429. : OVtoBitPlane() ( OpalScreen BitPlanes DestWidth Lines TopLine -- )
  430. \ Convert OpalVision bit plane data to standard bitplanes.
  431.    callvoid>abs Opal_LIB OVtoBitPlane
  432. ;
  433.  
  434. : FreezeFrame24() ( Freeze -- )
  435. \ Freezes the currently displayed screen.
  436.    callvoid Opal_LIB FreezeFrame24
  437. ;
  438.  
  439. : LowMemUpdate24() ( OpalScreen Frame -- OpalScreen/Error )
  440.    call>abs Opal_LIB LowMemUpdate24
  441.    dup OL_ERR_MAXERR >=    ( scr/error )
  442.    if >rel then            ( scr/error )
  443. ;
  444.  
  445. : DisplayThumbnail24() ( Screen 0Filename X Y -- Result )
  446. \ Displays a file's thumbnail.
  447.    call>abs Opal_LIB DisplayThumbnail24
  448. ;
  449.  
  450. : Config24() ( -- Result )
  451. \ Returns the OpalVision hardware configuration.
  452.    call Opal_LIB Config24
  453. ;
  454.  
  455. : AutoSync24() ( Sync -- )
  456. \ Enables auto horizontal synchronisation.
  457.    callvoid Opal_LIB AutoSync24
  458. ;
  459.  
  460. : DrawEllipse24() ( OpalScreen CX CY A B -- )
  461. \ Draw an ellipse of given dimensions.
  462.    callvoid>abs Opal_LIB DrawEllipse24
  463. ;
  464.  
  465. : DrawCircle24() ( opalScreen centerx centery radius -- , Draw circle )
  466. \ An alias for DrawEllipse24() for drawing circles.
  467.    dup DrawEllipse24()
  468. ;
  469.  
  470. : LatchDisplay24 ( Latch -- )
  471. \ Locks OpalVision display.
  472.    callvoid Opal_LIB LatchDisplay24
  473. ;
  474.  
  475. : SetHires24() ( Topline Lines -- )
  476. \ Enable a hires display for a section of the screen.
  477.    callvoid Opal_LIB SetHires24
  478. ;
  479.  
  480. : SetLores24() ( Topline Lines -- )
  481. \ Enable a lores display for a section of the screen.
  482.    callvoid Opal_LIB SetLores24
  483. ;
  484.  
  485. : DownLoadFrame24() ( OpalScreen X Y W H -- )
  486. \ ??
  487.    callvoid>abs Opal_LIB DownLoadFrame24
  488. ;
  489.  
  490. : SaveJPEG24() ( OpalScreen 0FileName Flags Quality -- Error )
  491. \ Save an OpalScreen as a JPEG JFIF file.
  492.    call>abs Opal_LIB SaveJPEG24
  493. ;
  494.  
  495. : LowMem2Update24() ( Screen Frame -- OpalScreen/Error )
  496. \ Low chip ram usage OpalVision update.
  497.    call>abs Opal_LIB LowMem2Update24
  498.    dup OL_ERR_MAXERR >=       ( scr/error )
  499.    if >rel then               ( scr/error )
  500. ;
  501.  
  502. : LowMemRGB24() ( ScreenModes Frame Width Height Modulo RGBPlanes -- )
  503. \ Low chip ram usage OpalVision update from an RGB array.
  504.    callvoid>abs Opal_LIB LowMemRGB24
  505.    dup OL_ERR_MAXERR >=       ( scr/error )
  506.    if >rel then               ( scr/error )
  507. ;
  508.  
  509.